<?php


class MsggItemHandlerFactory
{


    const DEFAULT_HANDLER='handler';
    const HANDLER_AFTER_HOOK='handlerAfterHook';
    const HANDLER_AFTER_EXECUTE='handlerAfterExecute';
    const HANDLER_BEFORE_EXECUTE = 'handlerBeforeExecute';

    private function __clone()
    {
        // TODO: Implement __clone() method.
    }

    private function __construct()
    {

    }

    public static function builds($eventTypes=[])
    {
        $handlers =[];
        if(!is_array($eventTypes))
        {
            $eventTypes = [$eventTypes,];
        }
        foreach ($eventTypes as $eventType)
        {
            switch ($eventType)
            {
                case MsggItem::EVENT_TYPE_ON_AFTER_EXECUTE:
                    if(!isset($handlers[MsggItem::EVENT_TYPE_ON_AFTER_EXECUTE]))
                    {
                        $handlers[MsggItem::EVENT_TYPE_ON_AFTER_EXECUTE] = [];
                    }
                    $handlers[MsggItem::EVENT_TYPE_ON_AFTER_EXECUTE][] = [new MsggItemHandler(), self::HANDLER_AFTER_EXECUTE];
                    break;
                case MsggItem::EVENT_TYPE_ON_AFTER_HOOK:
                    if(!isset($handlers[MsggItem::EVENT_TYPE_ON_AFTER_HOOK]))
                    {
                        $handlers[MsggItem::EVENT_TYPE_ON_AFTER_HOOK] = [];
                    }
                    $handlers[MsggItem::EVENT_TYPE_ON_AFTER_HOOK][] = [new MsggItemHandler(), self::HANDLER_AFTER_HOOK];
                    break;
                case MsggItem::EVENT_TYPE_ON_BEFORE_EXECUTE:
                    if(!isset($handlers[MsggItem::EVENT_TYPE_ON_BEFORE_EXECUTE]))
                    {
                        $handlers[MsggItem::EVENT_TYPE_ON_BEFORE_EXECUTE] = [];
                    }
                    $handlers[MsggItem::EVENT_TYPE_ON_BEFORE_EXECUTE][] = [new MsggItemHandler(), self::HANDLER_BEFORE_EXECUTE];
                    break;
                default:
                    if(!isset($handlers[$eventType]))
                    {
                        $handlers[$eventType] = [];
                    }
                    $handlers[$eventType][] = [new MsggItemHandler(), self::DEFAULT_HANDLER];
                    break;
                break;
            }
        }
        return $handlers;
    }


}